package com.sunpy.commonlock.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sunpy.commonlock.entity.CommonLockEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author sunpy
 * @since 2022-09-260
 */
@Component
@Mapper
public interface MysqlLockMapper extends BaseMapper<CommonLockEntity> {
    // 插入锁
    int insertLock(@Param("commonLockEntity") CommonLockEntity entity);
    // 根据lockId获取锁
    CommonLockEntity getLockByLockId(@Param("lockId") String lockId);
    // 根据lockName获取锁
    CommonLockEntity getLockByLockName(@Param("lockName") String lockName,
                                       @Param("author") String author);
    // 根据lockId删除锁
    int deleteLockByLockId(@Param("lockId") String lockId);
    // 根据lockName删除锁
    int deleteLockByLockName(@Param("lockName") String lockName,
                             @Param("author") String author);
    // 根据lockId删除超时的锁
    int deleteTimeoutLockByLockId(@Param("lockId") String lockId, @Param("nowTime") String nowTime);
    // 根据lockName删除超时的锁
    int deleteTimeoutLockByLockName(@Param("lockName") String lockName,
                            @Param("author") String author,
                            @Param("nowTime") String nowTime);
    // 根据lockId更新创建时间
    int updateLockByLockId(@Param("lockId") String lockId,
                           @Param("createtime") String createtime);
    // 根据lockName更新创建时间
    int updateLockByLockName(@Param("lockName") String lockName,
                             @Param("author") String author,
                             @Param("createtime") String createtime);
}
